﻿using System;
using System.Configuration;
using System.Collections.Generic;

using SBPweb.Communication.Shared.Library.Contacts;
using SBPweb.Communication.Shared.Library.Connections;

using SBPweb.Communication.Client.Library.Xmpp.Configuration;

namespace SBPweb.Communication.Client.Library.Xmpp.Connections
{

    public partial class ConnectionManagerConfigurationParser : ConfigurationParserBase, IConnectionManagerConfiguration
    {

        #region Constructor logic

        public ConnectionManagerConfigurationParser(IDictionary<string, string> parameters)
            : base(parameters)
        {
        }

        #endregion

        #region Property accessors

        protected override string Prefix
        {
            get
            {
                return "ConnectionManager";
            }
        }

        public string Server
        {
            get
            {
                return GetValue<string>("server", "sbpweb.hu");
            }
        }

        public int Port
        {
            get
            {
                return GetValue<Int32>("port", 4522);
            }
        }

        public string Resource
        {
            get
            {
                return GetValue<string>("resource", "SBPweb.Communication.Client.Library");
            }
        }

        public bool IsSslNeeded
        {
            get
            {
                return GetValue<bool>("isSslNeeded", false);
            }
        }

        public bool IsCompressionNeeded
        {
            get
            {
                return GetValue<bool>("isCompressionNeeded", false);
            }
        }

        public bool SendAvailabilityWhenConnected
        {
            get
            {
                return GetValue<bool>("sendAvailabilityWhenConnected", false);
            }
        }

        public AvailabilityTypes DefaultAvailability
        {
            get
            {
                try
                {
                    return (AvailabilityTypes)Enum.Parse(typeof(AvailabilityTypes), GetValue("defaultAvailability"), true);
                }
                catch
                {
                    return AvailabilityTypes.Available;
                }
            }
        }

        #endregion

    }

}